package com.mojian.service.impl;

import java.util.List;
import org.springframework.stereotype.Service;
import com.mojian.mapper.SysAccessLogMapper;
import com.mojian.entity.SysAccessLog;
import com.mojian.service.SysAccessLogService;
import com.mojian.utils.PageUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;

/**
 * 访问日志 服务实现类
 */
@Service
@RequiredArgsConstructor
public class SysAccessLogServiceImpl extends ServiceImpl<SysAccessLogMapper, SysAccessLog> implements SysAccessLogService {

    /**
     * 查询访问日志分页列表
     */
    @Override
    public IPage<SysAccessLog> selectPage(SysAccessLog sysAccessLog) {
        LambdaQueryWrapper<SysAccessLog> wrapper = new LambdaQueryWrapper<>();
        // 构建查询条件
        wrapper.eq(sysAccessLog.getId() != null, SysAccessLog::getId, sysAccessLog.getId());
        wrapper.eq(sysAccessLog.getUuid() != null, SysAccessLog::getUuid, sysAccessLog.getUuid());
        wrapper.eq(sysAccessLog.getIp() != null, SysAccessLog::getIp, sysAccessLog.getIp());
        wrapper.eq(sysAccessLog.getBrowserName() != null, SysAccessLog::getBrowserName, sysAccessLog.getBrowserName());
        wrapper.eq(sysAccessLog.getOs() != null, SysAccessLog::getOs, sysAccessLog.getOs());
        wrapper.eq(sysAccessLog.getUserAgent() != null, SysAccessLog::getUserAgent, sysAccessLog.getUserAgent());
        wrapper.eq(sysAccessLog.getCreateTime() != null, SysAccessLog::getCreateTime, sysAccessLog.getCreateTime());
        wrapper.eq(sysAccessLog.getUpdateTime() != null, SysAccessLog::getUpdateTime, sysAccessLog.getUpdateTime());
        return page(PageUtil.getPage(), wrapper);
    }

    /**
     * 查询访问日志列表
     */
    @Override
    public List<SysAccessLog> selectList(SysAccessLog sysAccessLog) {
        LambdaQueryWrapper<SysAccessLog> wrapper = new LambdaQueryWrapper<>();
        // 构建查询条件
        wrapper.eq(sysAccessLog.getId() != null, SysAccessLog::getId, sysAccessLog.getId());
        wrapper.eq(sysAccessLog.getUuid() != null, SysAccessLog::getUuid, sysAccessLog.getUuid());
        wrapper.eq(sysAccessLog.getIp() != null, SysAccessLog::getIp, sysAccessLog.getIp());
        wrapper.eq(sysAccessLog.getBrowserName() != null, SysAccessLog::getBrowserName, sysAccessLog.getBrowserName());
        wrapper.eq(sysAccessLog.getOs() != null, SysAccessLog::getOs, sysAccessLog.getOs());
        wrapper.eq(sysAccessLog.getUserAgent() != null, SysAccessLog::getUserAgent, sysAccessLog.getUserAgent());
        wrapper.eq(sysAccessLog.getCreateTime() != null, SysAccessLog::getCreateTime, sysAccessLog.getCreateTime());
        wrapper.eq(sysAccessLog.getUpdateTime() != null, SysAccessLog::getUpdateTime, sysAccessLog.getUpdateTime());
        return list(wrapper);
    }

    /**
     * 新增访问日志
     */
    @Override
    public boolean insert(SysAccessLog sysAccessLog) {
        return save(sysAccessLog);
    }

    /**
     * 修改访问日志
     */
    @Override
    public boolean update(SysAccessLog sysAccessLog) {
        return updateById(sysAccessLog);
    }

    /**
     * 批量删除访问日志
     */
    @Override
    public boolean deleteByIds(List<Long> ids) {
        return removeByIds(ids);
    }
}
